package com.atguigu.gmall.search.rpc;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.search.Goods;
import com.atguigu.gmall.search.repo.SearchRepo;
import com.atguigu.gmall.search.service.SearchService;
import com.atguigu.gmall.search.vo.SearchParamVo;
import com.atguigu.gmall.search.vo.SearchRespVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description
 * @Return
 * @Author https://weiranyi.github.io
 * @Date Created in 2022-12-12 15:12
 **/
@RestController
@RequestMapping("api/inner/rpc/search")
public class SearchRpcController {
    @Autowired
    SearchService searchService;
    // 上架代码 ES
    @PostMapping("/up/goods")
    public Result upGoodsToES(@RequestBody Goods goods) {
        searchService.upGoodsToES(goods);
        return Result.ok();
    }
    // 上架代码 ES
    @PostMapping("down/goods/{skuId}")
    public Result downGoodsToES(@PathVariable("skuId") Long skuId) {
        searchService.downGoodsToES(skuId);
        return Result.ok();
    }
    // 检索代码
    @PostMapping("/searchGoods")
    Result<SearchRespVo> search(@RequestBody SearchParamVo searchParamVo){
        SearchRespVo resp = searchService.search(searchParamVo);
        return Result.ok(resp);
    }
    // 更新热点分
    @PostMapping("/hotScore/{skuId}/{score}")
    Result autoIncrementHotScore(@PathVariable("skuId")Long skuId,@PathVariable("score")Long score){
        searchService.autoIncrementHotScore(skuId,score);
        return Result.ok();
    }
}
